/*     */ package com.zimbra.cs.mime;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.LogFactory;
/*     */ import javax.mail.MessagingException;
/*     */ import javax.mail.internet.MimeMessage;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ExpandMimeMessage
/*     */ {
/*  28 */   private static Log sLog = LogFactory.getLog(ExpandMimeMessage.class);
/*     */   private MimeMessage mMimeMessage;
/*     */   private MimeMessage mExpandedMessage;
/*     */   
/*     */   public ExpandMimeMessage(MimeMessage original)
/*     */   {
/*  34 */     this.mMimeMessage = original;
/*  35 */     this.mExpandedMessage = original;
/*     */   }
/*     */   
/*     */   private class ForkMimeMessage
/*     */     implements MimeVisitor.ModificationCallback
/*     */   {
/*     */     private ForkMimeMessage() {}
/*     */     
/*  43 */     private boolean mForked = false;
/*     */     
/*     */     public boolean onModification() {
/*  46 */       if (this.mForked) {
/*  47 */         return false;
/*     */       }
/*     */       try {
/*  50 */         this.mForked = true;
/*  51 */         ExpandMimeMessage.this.mExpandedMessage = new Mime.FixedMimeMessage(ExpandMimeMessage.this.mMimeMessage);
/*     */       } catch (Exception e) {
/*  53 */         ExpandMimeMessage.sLog.warn("Unable to fork MimeMessage.", e);
/*     */       }
/*  55 */       return false;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public MimeMessage getExpanded()
/*     */   {
/*  64 */     return this.mExpandedMessage;
/*     */   }
/*     */   
/*     */   public boolean wasExpanded() {
/*  68 */     return this.mExpandedMessage != this.mMimeMessage;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean expand()
/*     */     throws MessagingException
/*     */   {
/*  82 */     MimeVisitor.ModificationCallback forkCallback = new ForkMimeMessage(null);
/*     */     
/*     */     try
/*     */     {
/*  86 */       for (Class<? extends MimeVisitor> vclass : MimeVisitor.getConverters()) {
/*  87 */         if (this.mExpandedMessage == this.mMimeMessage) {
/*  88 */           ((MimeVisitor)vclass.newInstance()).setCallback(forkCallback).accept(this.mMimeMessage);
/*     */         }
/*  90 */         if (this.mExpandedMessage != this.mMimeMessage)
/*  91 */           ((MimeVisitor)vclass.newInstance()).accept(this.mExpandedMessage);
/*     */       }
/*     */     } catch (IllegalAccessException e) {
/*  94 */       this.mExpandedMessage = this.mMimeMessage;
/*  95 */       throw new MessagingException("Unable to instantiate MimeVisitor", e);
/*     */     } catch (InstantiationException e) {
/*  97 */       this.mExpandedMessage = this.mMimeMessage;
/*  98 */       throw new MessagingException("Unable to instantiate MimeVisitor", e);
/*     */     }
/*     */     
/* 101 */     return wasExpanded();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mime/ExpandMimeMessage.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */